package com.unipay.common.handler;

import com.unipay.common.result.ResultCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * @Project: yitong_parent
 * @Author: C.yu
 * @Time: 2023-03-27 20:57:54
 * @Desc: TODO 自定义全局异常类
 *      注意：
 *          自定义异常，需要在错误代码中，---throw 手动抛出
 *          1、try catch
 *          2、throwing new xxxException();
 */
@ApiModel(value = "自定义全局异常类")
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Data   //------自动生成其 getter()、setter()方法........
public class UnipayException extends RuntimeException {

    @ApiModelProperty(value = "异常状态码")
    private Integer code;
    @ApiModelProperty(value = "异常信息")
    private String message;

    /**
     * 通过状态码和错误消息创建异常对象
     * @param message
     * @param code
     */
    public UnipayException(String message, Integer code) {
        super(message);
        this.code = code;
    }
    /**
     * 接收枚举类型对象
     * @param resultCodeEnum
     */
    public UnipayException(ResultCodeEnum resultCodeEnum) {
        // this.message = resultCodeEnum.getMessage();
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

    @Override
    public String toString() {
        return "YyghException{" +
                "code=" + code +
                ", message=" + this.getMessage() +
                '}';
    }
}
